#include <bits/stdc++.h>
// 2025/02/07
// tag:
// Author: Zhang Muen
using namespace std;
class State
{
public:
    int64_t id, weight;
    State(int i, int w)
    {
        id = i;
        weight = w;
    }
};

struct cmp
{
    bool operator()(State &a, State &b)
    {
        return a.weight > b.weight;
    }
};

u_int64_t n, m, b, dist[10001], f[10001];
vector<State> graph[10001];

bool check(int64_t money)
{
    for (int i = 1; i <= n; i++)
        dist[i] = INT64_MAX;
    priority_queue<State, vector<State>, cmp> pq;
    dist[1] = 0;
    pq.push(State(1, 0));
    while (!pq.empty())
    {
        State state = pq.top();
        pq.pop();
        if (f[state.id] > money)
            continue;
        int Dist = state.weight;
        if (Dist > dist[state.id])
            continue;
        for (auto neighbor : graph[state.id])
        {
            if (f[neighbor.id] > money)
                continue;
            int Dist2 = Dist + neighbor.weight;
            if (dist[neighbor.id] > Dist2)
            {
                dist[neighbor.id] = Dist2;
                pq.push(State(neighbor.id, Dist2));
            }
        }
    }
    return dist[n] <= b;
}

signed main()
{
    cin >> n >> m >> b;
    int64_t u, v, w;
    for (int i = 1; i <= n; i++)
        cin >> f[i];
    for (int i = 0; i < m; i++)
    {
        cin >> u >> v >> w;
        graph[u].push_back(State(v, w));
        graph[v].push_back(State(u, w));
    }
    int l = 0, r = 1e9;
    if (!check(1e9))
    {
        cout << "AFK";
        return 0;
    }
    while (l <= r){
        int mid = (l + r) / 2;
        if (check(mid))
            r = mid - 1;
        else
            l = mid + 1;
    }
    cout << l;
    return 0;
}